package com.emergency.db.controller.info;


import com.emergency.common.entity.Result;
import com.emergency.common.entity.StatusCode;
import com.emergency.db.domain.info.Rescue;
import com.emergency.db.service.info.RescueService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import java.util.List;
import java.util.Map;

//突击抢险一队总表控制
@RestController
@RequestMapping("/rescue")
@CrossOrigin
public class RescueController {
    @Autowired
    private RescueService rescueService;


    //保存
    @RequestMapping(value = "/save", method = RequestMethod.POST)
    public Result save(@RequestBody Rescue rescue) {
        Long id = rescueService.save(rescue);
        return new Result(true, StatusCode.OK, "保存成功", id);
    }

    //查询单项
    @RequestMapping(value = "/search/{rescueId}", method = RequestMethod.POST)
    public Result findById(@PathVariable("rescueId") Long rescueId) {
        Rescue rescue = rescueService.findById(rescueId);
        return new Result(true, StatusCode.OK, "查询成功", rescue);
    }

    //删除
    @RequestMapping(value = "/del/{rescueId}", method = RequestMethod.POST)
    public Result delete(@PathVariable Long rescueId) {
        rescueService.delete(rescueId);
        return new Result(true, StatusCode.OK, "删除成功");
    }

    //分页
    @RequestMapping(value = "list/{page}/{size}", method = RequestMethod.POST)
    public Result list(@RequestBody Map searchMap, @PathVariable int page, @PathVariable int size) {
        Page<Rescue> pageList = rescueService.findList(searchMap, page, size);
        return new Result(true, StatusCode.OK, "操作成功", pageList);
    }
}
